<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    function Stack() {
   var items = [];

  // 添加一个（或几个）新元素到栈顶
  this.push = function(ele) {
    items.push(ele);
  };
    
  // 移除栈顶的元素，同时返回被移除的元素
  this.pop = function() {
    return items.pop();
  };

  // 返回栈顶的元素，不对栈做任何修改
  this.peek = function() {
    return items[items.length - 1];
  };

  // 判断栈里使是否还有元素
  this.isEmpty = function() {
    return items.length == 0;
  };

  // 移除栈里所有的元素
  this.clear = function() {
    items = [];
  };

  // 返回栈里的元素个数
  this.size = function() {
    return items.length;
  };

  this.print = function() {
    console.log(items.toString());
  };
}
var stack = new Stack();
console.log(stack.isEmpty());
stack.push(1);
stack.push(8);
console.log(stack.peek());
stack.push(10);
console.log(stack.peek());
console.log(stack.size());
console.log(stack.isEmpty());
console.log(14)
stack.pop();
stack.pop();
stack.print();
//
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"

document.write(arr + "<br />")
document.write(arr.push("James") + "<br />")
document.write(arr)

</script>
</html>